package com.spyx.product.service.impl;

import com.atyx.spyx.model.product.AttrGroup;
import com.atyx.spyx.vo.product.AttrGroupQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spyx.product.mapper.AttrGroupMapper;
import com.spyx.product.service.AttrGroupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 属性分组 服务实现类
 * </p>
 *
 * @author yhp
 * @since 2024-05-15
 */
@Service
public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupMapper, AttrGroup> implements AttrGroupService {

    @Override
    public IPage<AttrGroup> getGroupList(Page page, AttrGroupQueryVo vo) {
        //1.获取模糊查条件
        String name = vo.getName();
        //2.封装模糊查条件
        LambdaQueryWrapper<AttrGroup> wrapper = new LambdaQueryWrapper<AttrGroup>();
        if(!StringUtils.isEmpty(name)){
            wrapper.like(AttrGroup::getName,name);
        }
        //3.执行查询
        Page pageModel = baseMapper.selectPage(page, wrapper);

        return pageModel;
    }

    @Override
    public List<AttrGroup> findAllList() {
        return baseMapper.selectList(null);
    }
}
